//
//  LGCancerInspectTableController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/19.
//

#import "LGCancerInspectTableController.h"
#import "LGCancerPatientReportCell.h"
@interface LGCancerInspectTableController ()<UITableViewDelegate,UITableViewDataSource,LGCancerPatientReportDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSMutableArray *openArray;
/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation LGCancerInspectTableController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:self.tableView.frame];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/patient.Report/groupList" parameters:@{@"patient_id":self.patientid,@"group":self.type} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (code == 200) {
            self.dataArray = returnData;
            [self.tableView reloadData];
        }
        if (self.dataArray.count == 0) {
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无报告" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (self.dataArray.count == 0) {
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无报告" offset:0];
        }
    }];
}

-(void)reportCellOpend:(BOOL)opend index:(NSInteger)index{
    if (opend == YES) {
        [self.openArray addObject:@(index)];
    }else{
        [self.openArray removeObject:@(index)];
    }
    [self.tableView reloadData];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGCancerPatientReportCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleKey = [self.type isEqualToString:@"date"]?@"type":@"title";
    cell.opened = [self.openArray containsObject:@(indexPath.row)]?YES:NO;
    cell.dataDic = self.dataArray[indexPath.row];
    cell.index = indexPath.row;
    cell.delegate = self;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    return headView;
}
-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight-viewPix(44)) style:UITableViewStylePlain];
        [_tableView registerClass:[LGCancerPatientReportCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

-(NSMutableArray *)openArray{
    if(!_openArray){
        _openArray = [NSMutableArray array];
    }
    return _openArray;
}
@end
